"use strict";
cc._RF.push(module, '488e5pBdTJCzKE49mqhA8bg', 'NativeAd_Oppo_Android_Single');
// scripts/NativeAd_Oppo_Android_Single.js

"use strict";

var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
  value: !0
});

var o = e("NativeAdBase"),
    i = cc._decorator,
    a = i.ccclass,
    r = i.property,
    s = function (e) {
  __extends(t, e);

  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.autoShow = !0;
    t.autoFresh = !0;
    t.delay = 0;
    t.protect = !1;
    t.adNode = null;
    t.title = null;
    t.desc = null;
    t.iconSprite = null;
    t.mainSprite = null;
    t.nativeItem = null;
    t.closeBtn = null;
    t.extentBtns = [];
    t.showState = 0;
    t.keyName = "closeBtnNativeProbability";
    return t;
  }

  t.prototype.onEnable = function () {
    var e = this;

    if (SDK.Mgr.Inst.curChannel == SDK.Define.Channel.android_oppo) {
      this.protect && !SDK.Mgr.Inst.isAdOpen && this.hide();
      SDK.Base.Event.on("onFreshNativeAdData", this.onFresh, this);
      SDK.Base.Event.on("onGetNativeAd", this.onGetAD, this);

      if (this.autoShow) {
        this.unscheduleAllCallbacks();
        this.scheduleOnce(function () {
          e.show();
        }, this.delay);
        this.autoFresh && this.schedule(function () {
          e.show();
        }, SDK.Mgr.Inst.nativeFreshTime + 1, cc.macro.REPEAT_FOREVER, this.delay);
      }
    }
  };

  t.prototype.onDisable = function () {
    if (SDK.Mgr.Inst.curChannel == SDK.Define.Channel.android_oppo) {
      SDK.Base.Event.off("onFreshNativeAdData", this.onFresh, this);
      SDK.Base.Event.off("onGetNativeAd", this.onGetAD, this);
    }
  };

  t.prototype.onFresh = function (e) {
    this.nativeItem && e == this.nativeItem.adId && this.show();
  };

  t.prototype.onGetAD = function () {
    1 == this.showState && this.show();
  };

  t.prototype.canShow = function () {
    return SDK.Mgr.Inst.getAds().hasNative();
  };

  t.prototype.show = function () {
    this.showState = 1;

    if (this.canShow()) {
      this.showState = 2;
      var e = SDK.Mgr.Inst.getAds().getNative();
      this.nativeItem = e;
      this.nativeItem.show();
      this.adNode && (this.adNode.active = !0);
      this.closeBtn && (this.closeBtn.active = !0);
      this.extentBtns.forEach(function (e) {
        e.active = !0;
      });
      this.title && (this.title.string = this.nativeItem.title);
      this.desc && (this.desc.string = this.nativeItem.desc);
      this.iconSprite && (this.nativeItem.iconUrl ? SDK.Util.Helper.loadImage(this.iconSprite, this.nativeItem.iconUrl) : this.nativeItem.imgUrl && SDK.Util.Helper.loadImage(this.iconSprite, this.nativeItem.imgUrl));
      this.mainSprite && (this.nativeItem.imgUrl ? SDK.Util.Helper.loadImage(this.mainSprite, this.nativeItem.imgUrl) : this.nativeItem.iconUrl && SDK.Util.Helper.loadImage(this.mainSprite, this.nativeItem.iconUrl));
    } else {
      var t = this,
          n = function n() {
        if (t.canShow()) {
          t.unschedule(n);
          t.show();
        }
      };

      this.schedule(n, .2, 25);
    }
  };

  t.prototype.click = function () {
    if (this.nativeItem) {
      this.hide();
      SDK.Mgr.Inst.getAds().clickNative();
      this.nativeItem.click();
    }
  };

  t.prototype.hide = function () {
    this.node && this.node.isValid && this.node.destroy();
  };

  t.prototype.close = function () {
    SDK.Mgr.Inst.isAdOpen && SDK.Mgr.Inst.customData && SDK.Mgr.Inst.customData[this.keyName] && Math.random() < SDK.Mgr.Inst.customData[this.keyName] && this.click();
    SDK.Mgr.Inst.getAds().closeNative();
    this.hide();
  };

  __decorate([r(cc.Boolean)], t.prototype, "autoShow", void 0);

  __decorate([r(cc.Boolean)], t.prototype, "autoFresh", void 0);

  __decorate([r(cc.Float)], t.prototype, "delay", void 0);

  __decorate([r(cc.Boolean)], t.prototype, "protect", void 0);

  __decorate([r(cc.Node)], t.prototype, "adNode", void 0);

  __decorate([r(cc.Label)], t.prototype, "title", void 0);

  __decorate([r(cc.Label)], t.prototype, "desc", void 0);

  __decorate([r(cc.Sprite)], t.prototype, "iconSprite", void 0);

  __decorate([r(cc.Sprite)], t.prototype, "mainSprite", void 0);

  __decorate([r(cc.Node)], t.prototype, "closeBtn", void 0);

  __decorate([r([cc.Node])], t.prototype, "extentBtns", void 0);

  return __decorate([a], t);
}(o["default"]);

n["default"] = s;

cc._RF.pop();